package com.lovo.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.project.bean.UserBean;
import com.lovo.project.mapper.UserMapper;
import com.lovo.project.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserBean> implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public UserBean queryUser(QueryWrapper queryWrapper) {
        UserBean userBean=userMapper.selectOne(queryWrapper);
        return userBean;
    }

    @Override
    public Page<UserBean> selectUserList(Page<UserBean> page, QueryWrapper<UserBean> queryWrapper) {
        Page<UserBean> page1=userMapper.selectPage(page,queryWrapper);
        return page1;
    }

    @Override
    public void deleteUser(Integer id) {
        userMapper.deleteById(id);
    }

    @Override
    public void addUser(UserBean userBean , List<Integer> roleId) {
        userMapper.insert(userBean);
        userMapper.insertRole(userBean.getUserId(),roleId);
    }

    @Override
    public void updatePassword(UserBean userBean) {
        userMapper.updateById(userBean);
    }
}
